package com.xzq.erp.controller;


import com.xzq.erp.aspect.ApiOperationLog;
import com.xzq.erp.domain.dto.AfterSalesServiceDTO;
import com.xzq.erp.domain.dto.PageDTO;
import com.xzq.erp.domain.query.AfterSalesServicePageQuery;
import com.xzq.erp.domain.vo.AfterSalesServiceVO;
import com.xzq.erp.service.IAfterSalesServiceService;
import com.xzq.erp.service.IFileService;
import com.xzq.erp.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 文件上传前端控制器
 * </p>
 *
 * @author xzq
 * @since 2025-05-16
 */
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
@Tag(name = "文件上传相关接口")
public class FileController {

    private final IFileService fileService;

    /**
     * 分页查询文件上传列表
     */
    @PostMapping("/upload")
    @Operation(summary = "上传文件")
    @ApiOperationLog(description = "上传文件")
    public Response<String> fileUpload(@RequestParam MultipartFile file) {
        return Response.success(fileService.fileUpload(file));
    }

    /**
     * 删除文件
     */
    @DeleteMapping("/{fileName}")
    @Operation(summary = "删除文件")
    @ApiOperationLog(description = "删除文件")
    public Response<Void> deleteFile(@PathVariable String fileName) {
        fileService.deleteFile(fileName);
        return Response.success();
    }

    /**
     * 批量删除文件
     */
    @DeleteMapping
    @Operation(summary = "批量删除文件")
    @ApiOperationLog(description = "批量删除文件")
    public Response<Void> deleteFiles(@RequestBody @NotEmpty List<String> fileNames) {
        fileService.deleteFiles(fileNames);
        return Response.success();
    }

}
